package com.example.red_tea_house.moudle.SystemSetting.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;

import com.example.red_tea_house.MyApplication;
import com.example.red_tea_house.R;
import com.example.red_tea_house.entity.UserBean;
import com.example.red_tea_house.entity.setRecyclerViewNameBean;
import com.example.red_tea_house.moudle.SystemSetting.Adapter.SystemSettingAdapter;
import com.example.red_tea_house.util.ToastUtil;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class SystemSettingActivity extends AppCompatActivity {

    private Context context= MyApplication.getContext();
    private List<setRecyclerViewNameBean> data = new ArrayList<>();
    private Intent intent;

    private Button exitLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.system_setting);

        exitLogin=findViewById(R.id.exit_login);

        setItemBeans();

        RecyclerView recyclerView = findViewById(R.id.system_setting_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(new SystemSettingAdapter(data,context,SystemSettingActivity.this));

        exitLogin.setOnClickListener((v)->{
            exitLogin();
        });

    }
    private void setItemBeans() {
        setRecyclerViewNameBean bean1 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean2 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean3 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean4 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean5 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean6 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean7 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean8 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean9 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean10 = new setRecyclerViewNameBean();
        setRecyclerViewNameBean bean11 = new setRecyclerViewNameBean();
        bean1.setName("账号管理");data.add(bean1);
        bean2.setName("隐私设置");data.add(bean2);
        bean3.setName("账号安全");data.add(bean3);
        bean4.setName("偏好设置");data.add(bean4);
        bean5.setName("屏蔽设置");data.add(bean5);
        bean6.setName("消息通知");data.add(bean6);
        bean7.setName("夜间模式");data.add(bean7);
        bean8.setName("关于红茶馆");data.add(bean8);
        bean9.setName("清除缓存");data.add(bean9);
        bean10.setName("建议与反馈");data.add(bean10);
        bean11.setName("检查更新");data.add(bean11);

    }
    private void exitLogin(){
        ToastUtil.showToast(context,"退出成功");
        LitePal.deleteAll(UserBean.class,"id>?","0");

        //重启程序
        Intent i = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(getBaseContext().getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
    }

    public void turnPage(String pageName){
        if(pageName.equals(getString(R.string.about_red_tea_house))){
            intent=new Intent(SystemSettingActivity.this,AboutUsActivity.class);
        }else if(pageName.equals(getString(R.string.account_manage))){
            intent=new Intent(SystemSettingActivity.this,AccountManageActivity.class);
        }else if(pageName.equals(getString(R.string.account_security))){
            intent=new Intent(SystemSettingActivity.this,AccountSecurityActivity.class);
        }else if(pageName.equals(getString(R.string.advice_and_feedback))){
            intent=new Intent(SystemSettingActivity.this,AdviceAndFeedbackActivity.class);
        }else if(pageName.equals(getString(R.string.check_for_updates))){
            intent=new Intent(SystemSettingActivity.this,CheckForUpdataActivity.class);
        }else if(pageName.equals(getString(R.string.clear_cache))){
            intent=new Intent(SystemSettingActivity.this,ClearCacheActivity.class);
        }else if(pageName.equals(getString(R.string.news_inform))){
            intent=new Intent(SystemSettingActivity.this,NewsInformActivity.class);
        }else if(pageName.equals(getString(R.string.night_mode))){
            intent=new Intent(SystemSettingActivity.this,NightModeActivity.class);
        }else if(pageName.equals(getString(R.string.prefer_setting))){
            intent=new Intent(SystemSettingActivity.this,PreferringSettingActivity.class);
        }else if(pageName.equals(getString(R.string.privacy_setting))){
            intent=new Intent(SystemSettingActivity.this,PrivacySettingActivity.class);
        }else if(pageName.equals(getString(R.string.shielding_setting))){
            intent=new Intent(SystemSettingActivity.this,ShieldingSettingActivity.class);
        }
        startActivity(intent);
    }
}